package com.BigDate.server.controller;


import com.BigDate.server.pojo.ForkProject;
import com.BigDate.server.pojo.User;
import com.BigDate.server.service.IForkProjectService;
import com.BigDate.server.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stx
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/fork-project")
public class ForkProjectController {
    @Autowired
    private IForkProjectService forkProjectService;
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "根据id展示fork记录")
    @GetMapping("/{projectId}")
    private List<ForkProject> getProjectFork(@PathVariable("projectId") Integer projectId){
        List<ForkProject> forkProjectList = forkProjectService.list(new QueryWrapper<ForkProject>()
                .eq("projectid",projectId));
        for (ForkProject forkProject : forkProjectList) {
            User user = userService.getById(forkProject.getUserid());
            forkProject.setNickname(user.getNickname());
        }
        System.out.println(forkProjectList);
        return forkProjectList;
    }
}
